import django_filters
from django.contrib.auth.models import Group, User


class RoleFilter(django_filters.rest_framework.FilterSet):

    class Meta:
        model = Group
        fields = fields = {
            "name": ['contains', 'exact'],
            "id": ['in', 'exact'],
        }


class UserFilter(django_filters.rest_framework.FilterSet):
    group_id__in = django_filters.CharFilter(method='group_id__in_func')

    def group_id__in_func(self, queryset, name, value):
        return queryset.filter(groups__in=value.split(','))

    class Meta:
        model = User
        fields = {
            "id": ['in', 'exact'],
            "username": ['contains', 'exact'],

        }
